<?php
/**
 * Created by PhpStorm.
 * User: ZNZG
 * Date: 2022/3/1
 * Time: 18:24
 */

namespace app\common\lib;


use app\common\exception\BaseException;

class Show
{
    /**
     * 显示操作结果
     * @param $data
     * @param string $msg
     * @return \think\response\Json
     * @throws BaseException
     */
    public static function success($data,$msg = '')
    {
        if(is_array($data) || is_numeric($data) || $data){
            $result = [
                'code' => 200,
                'msg' => '操作成功',
                'errorCode' => 0
            ];
            if($msg){
                $result['msg'] = $msg;
            }
            $result['data'] = $data;

            return json($result,$result['code']);
        }

        throw new BaseException($msg?$msg:'操作失败');
    }
}